using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

namespace OracleInternal.ServiceObjects
{
	internal class DotNetXmlValidator
	{
		internal Exception m_validatingException;

		internal bool m_bHasError;

		internal XmlReaderSettings m_readerSettings;

		internal DotNetXmlValidator(string xslSchema)
		{
			m_readerSettings = CreateReaderValidationSettings(xslSchema);
		}

		internal XmlReaderSettings CreateReaderValidationSettings(string xslSchema)
		{
			XmlReaderSettings obj = new XmlReaderSettings
			{
				ValidationType = ValidationType.Schema
			};
			obj.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.ReportValidationWarnings;
			obj.ValidationEventHandler += ValidationEventHandler;
			obj.Schemas.Add(null, XmlReader.Create(new StringReader(xslSchema)));
			return obj;
		}

		internal bool Validate(XmlReader xmlReaderToValidate)
		{
			try
			{
				while (xmlReaderToValidate.Read() && !m_bHasError)
				{
				}
			}
			catch (Exception validatingException)
			{
				m_bHasError = true;
				m_validatingException = validatingException;
			}
			return !m_bHasError;
		}

		private void ValidationEventHandler(object sender, ValidationEventArgs e)
		{
			if (e.Severity == XmlSeverityType.Error)
			{
				m_bHasError = true;
			}
			m_validatingException = e.Exception;
		}
	}
}
